package visual;


import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class KML2KMZ {

  public static void run(String kmz_file) throws Exception {
	final int BUFFER = 2048;
	byte data[] = new byte[BUFFER];
	
	String kml_file = kmz_file.substring(0,kmz_file.indexOf(".kmz"))+".kml";
	File f = new File(kml_file);
	
	ZipOutputStream kmz = new ZipOutputStream(new FileOutputStream(kmz_file));
    kmz.putNextEntry(new ZipEntry(f.getName()));
    BufferedInputStream kml = new BufferedInputStream(new FileInputStream(kml_file), BUFFER);
    
    int count;
    while((count = kml.read(data, 0, BUFFER)) != -1) 
         kmz.write(data, 0, count);     
   
    kml.close();
    kmz.closeEntry();
    kmz.close();
    
    f.delete();
  }  
}